package com.yy.controller;

import com.yy.domain.SysMenu;
import com.yy.model.Result;
import com.yy.service.SysMenuService;
import com.yy.utils.AuthUtil;
import com.yy.vo.MenuPermsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * 描述: [菜单管理接口]
 * 作者: 雷哥(LEO)
 * 邮箱: 78414842@qq.com
 */
@RestController
@Api(tags = "菜单管理接口")
@RequestMapping("sys/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 拿当前用户的id
     * 查菜单数据--- 树形结构
     * 拿权限集合
     *
     * @return
     */
    @GetMapping("nav")
    @ApiOperation("加载当前用户的菜单和权限集合")
    public Result<MenuPermsVO> loadMenuAndPerms() {
        Long userId = AuthUtil.getUserId();
        // 查菜单
        List<SysMenu> sysMenus = sysMenuService.findUserMenus(userId);
        Set<String> perms = AuthUtil.getPerms();
        MenuPermsVO menuPermsVO = new MenuPermsVO(sysMenus, perms);

        return Result.success(menuPermsVO);
    }




}
